package co.yixiang.auth.exception;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator;

/**
 * OAuth2 自定义异常处理
 *
 * @author yshop
 */
public class CustomWebResponseExceptionTranslator implements WebResponseExceptionTranslator<OAuth2Exception>
{
//    private static final String INVALID_TOKEN_ERROR_DESCRIPTION = "Token was not recognised";//token 无效
//    private static final String INVALID_AUTHORIZATION_CODE = "Invalid authorization code";//授权码无效
//    private static final String INVALID_USER = "无效用户";//密码有误
//    private static final String BAD_CREDENTIALS = "Bad credentials";//密码有误


    @Override
    public ResponseEntity<OAuth2Exception> translate(Exception e)
    {
//        if(INVALID_TOKEN_ERROR_DESCRIPTION.equals(e.getMessage())){
//            return ResponseEntity.status(HttpStatus.OK).body(new CustomOauthException("请重新登录"));
//        }
        return ResponseEntity.status(HttpStatus.OK).body(new CustomOauthException(e.getMessage()));
    }
}
